package com.cc.controller;

import com.cc.entity.User;
import com.cc.serive.AuthService;
import com.cc.util.JsonResult;
import com.cc.util.JwtUtil;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @program:
 * @ClassName:
 * @description:
 * @author: zgc
 * @date:
 * @Version 1.0
 **/
@RestController
@RefreshScope
public class AuthController {

//    private CloseableHttpClient CloseableHttpClient;
   @Resource
   private AuthService authService;

    @Resource
    JwtUtil jwtUtil;

    @RequestMapping("/tologin")
    public JsonResult tologin(String accountName, String password, HttpServletResponse response) throws IOException {

        System.out.println(accountName+"="+password);
        User user = authService.authLogin(accountName, password);
        if (user!=null){
            String token = jwtUtil.createToken(accountName);
            System.out.println(token);
            response.setHeader("token",token);
            return JsonResult.success(user);
        }
        return JsonResult.error();
    }

}
